package org.dbstar.scheduler.control.db.catalog;

import java.sql.Types;

import org.dbstar.scheduler.beans.Catalog;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.object.SqlUpdate;


/**
 * CataLog的Update对象
 * 
 * @author 代波
 * @since 1.0.0
 * @version 1.0.0
 * @date 2012-4-21
 */
public class CatalogUpdate extends SqlUpdate {
	public CatalogUpdate(JdbcTemplate jdbcTemplate) {
		super();
		setJdbcTemplate(jdbcTemplate);
		setSql("UPDATE SCHD_CATALOG SET NAME=?, PARENT=?, DESCRIPTION=?, MODIFY_TIME=?, OWNER=?, MODIFIER=? WHERE ID=?");
		declareParameter(new SqlParameter("NAME", Types.VARCHAR));
		declareParameter(new SqlParameter("PARENT", Types.INTEGER));
		declareParameter(new SqlParameter("DESCRIPTION", Types.VARCHAR));
		declareParameter(new SqlParameter("MODIFY_TIME", Types.BIGINT));
		declareParameter(new SqlParameter("OWNER", Types.VARCHAR));
		declareParameter(new SqlParameter("MODIFIER", Types.VARCHAR));
		declareParameter(new SqlParameter("ID", Types.INTEGER));
	}

	public int updateCatalog(Catalog info) {
		long modifyTime = System.currentTimeMillis();
		int result = update(info.getName(), info.getParent(), info.getDescription(), modifyTime, info.getOwner(),
				info.getModifier(), info.getId());
		info.setModifyTime(modifyTime);
		return result;
	}
}
